home *** CD-ROM | disk | FTP | other *** search
/ Professional Soft Collection 1.02 / Professional Soft Collection 1.02.iso / communic / qmodempr / script.pak / HOST.SCR < prev    next >
Encoding:
Text File  |  1994-03-01  |  17.4 KB  |  699 lines

  1. '
  2. ' Host mode script for QmodemPro for Windows.
  3. '
  4. ' Version 1.0
  5. '
  6. ' Last updated February 26, 1993.
  7. '
  8.  
  9. '$include 'hostutil.scr'
  10.  
  11. ' Constants
  12.  
  13. const BS  = chr(8)
  14. const LF  = chr(10)
  15. const CR  = chr(13)
  16. const ESC = chr(27)
  17.  
  18. const PrelogFileNamePart   = "host.pre"
  19. const MenuFileNamePart     = "host.mnu"
  20. const ProtocolFileNamePart = "host.pro"
  21. const LogoffFileNamePart   = "host.off"
  22. const HelpFileNamePart     = "host.hlp"
  23.  
  24. const UserFileNamePart      = "host.usr"
  25. const MsgHeaderFileNamePart = "host.hdr"
  26. const MsgDetailFileNamePart = "host.msg"
  27.  
  28. const MaxMsgLines = 99
  29.  
  30. ' Type declarations
  31.  
  32. dialog SetupDialog 18, 18, 214, 200
  33.   caption "QmodemPro Host Setup"
  34.   groupbox "Mode", 101, 18, 9, 74, 64
  35.   modeopen as radiobutton "Open", 102, 26, 23, 62, 12
  36.   modeclosed as radiobutton "Closed", 103, 26, 38, 62, 12
  37.   modecallback as radiobutton "Callback", 104, 26, 53, 62, 12
  38.   groupbox "Security", 150, 100, 9, 100, 64
  39.   maxtime as edittext 105, 151, 22, 42, 12
  40.   dospass as edittext 106, 151, 39, 42, 12
  41.   shutdownpass as edittext 107, 151, 56, 42, 12
  42.   rtext "Max time", -1, 108, 25, 41, 8
  43.   rtext "DOS pwd", -1, 108, 41, 41, 8
  44.   rtext "Shutdown pwd", -1, 108, 59, 41, 8
  45.   groupbox "File transfers", 160, 18, 80, 182, 85
  46.   dlpath as edittext 108, 22, 104, 169, 12
  47.   ulpath as edittext 109, 22, 130, 169, 12
  48.   ltext "Download path", -1, 24, 95, 62, 8
  49.   ltext "Upload path", -1, 24, 120, 69, 8
  50.   sysopanypath as checkbox "Sysop can download from any path", 110, 25, 148, 165, 12
  51.   pushbutton "&Modem...", 200, 15, 175, 50, 14
  52.   defpushbutton "OK", IDOK, 80, 175, 50, 14
  53.   pushbutton "Cancel", IDCANCEL, 150, 175, 50, 14
  54. end dialog
  55.  
  56. dialog ModemSetupDialog 6, 15, 194, 119
  57.   caption "QmodemPro Host Modem Setup"
  58.   groupbox "", -1, 8, 9, 177, 79
  59.   init as edittext 101, 48, 17, 127, 12
  60.   answer as edittext 102, 48, 33, 47, 12
  61.   busy as edittext 103, 48, 49, 47, 12
  62.   ok as edittext 104, 48, 65, 47, 12
  63.   ring as edittext 105, 129, 33, 45, 12
  64.   ringcount as edittext 106, 148, 49, 27, 12
  65.   rtext "&Init", -1, 16, 19, 28, 8
  66.   rtext "&Answer", -1, 12, 34, 33, 8
  67.   rtext "&Busy", -1, 12, 50, 33, 8
  68.   rtext "&OK msg", -1, 13, 66, 32, 8
  69.   rtext "&Ring", -1, 105, 35, 20, 8
  70.   rtext "Ring &Count", -1, 106, 51, 38, 8
  71.   defpushbutton "OK", IDOK, 77, 96, 50, 14
  72.   pushbutton "Cancel", IDCANCEL, 137, 96, 50, 14
  73. end dialog
  74.  
  75. type TUser
  76.   Name as string*25
  77.   Password as string*20
  78.   Level as integer
  79.   Phone as string*30
  80. end type
  81.  
  82. type TMessageHeader
  83.   Sender as string*25
  84.   Receiver as string*25
  85.   Subject as string*75
  86.   DateTime as string*20
  87.   Private as integer
  88.   Received as integer
  89.   Killed as integer
  90.   Lines as integer
  91.   Detailpos as long
  92. end type
  93.  
  94. ' connection variables
  95. dim Local as integer
  96. dim Port as integer
  97. dim ModemResult as string
  98. dim BaudRate as long
  99. dim LogonTime as DateTimeRec
  100. dim LogoffTime as DateTimeRec
  101. dim ForceLogoff as integer
  102.  
  103. dim Setup as SetupDialog
  104. dim ModemSetup as ModemSetupDialog
  105. dim User as TUser
  106. dim MsgLines(MaxMsgLines) as string
  107.  
  108. dim PrelogFileName as string
  109. dim MenuFileName as string
  110. dim ProtocolFileName as string
  111. dim LogoffFileName as string
  112. dim HelpFileName as string
  113. dim UserFileName as string
  114. dim MsgHeaderFileName as string
  115. dim MsgDetailFileName as string
  116.  
  117. '$include 'hostcfg.scr'
  118.  
  119. declare sub PackMessages
  120.  
  121. ' Utility routines
  122.  
  123. sub GetCurrentTime(dt as DateTimeRec)
  124.   do
  125.     dt.D = Today
  126.     dt.T = CurrentTime
  127.   loop until dt.D = Today
  128. end sub
  129.  
  130. function MinutesSince(dt as DateTimeRec)
  131.   dim now as DateTimeRec
  132.   call GetCurrentTime(now)
  133.   while now.D > dt.D
  134.     now.D = now.D - 1
  135.     now.T = now.T + SecondsInDay
  136.   wend
  137.   MinutesSince = (now.T - dt.T) / 60
  138. end function
  139.  
  140. function MinutesUntil(dt as DateTimeRec)
  141.   dim now as DateTimeRec
  142.   call GetCurrentTime(now)
  143.   while dt.D > now.D
  144.     now.D = now.D + 1
  145.     now.T = now.T - SecondsInDay
  146.   wend
  147.   MinutesUntil = (dt.T - now.T) / 60
  148. end function
  149.  
  150. function TimeLeft as integer
  151.   TimeLeft = MinutesUntil(LogoffTime)
  152. end function
  153.  
  154. function CallerHungUp as integer
  155.   CallerHungUp = (not Local and not Carrier) or ForceLogoff
  156. end function
  157.  
  158. sub DoChat
  159.   dim s as string, c as string
  160.   send #Port,
  161.   send #Port, "You are now chatting with the sysop"
  162.   send #Port,
  163.   do
  164.     c = inkey
  165.     if c = "F2" then
  166.       exit do
  167.     end if
  168.     if c = "" and not Local then
  169.       c = inkey(Port)
  170.     end if
  171.     select case c
  172.       case BS
  173.         if len(s) > 0 then
  174.           s = left(s, len(s)-1)
  175.           send #Port, BS; " "; BS;
  176.         end if
  177.       case CR
  178.         send #Port,
  179.         s = ""
  180.       case is >= " "
  181.         if len(c) = 1 then
  182.           s = s + c
  183.           send #Port, c;
  184.           if len(s) >= 79 then
  185.             if instr(s, " ") then
  186.               dim i as integer
  187.               i = len(s)
  188.               while mid(s, i, 1) <> " "
  189.                 i = i - 1
  190.               wend
  191.               send #Port, string(len(s)-i, BS); string(len(s)-i, " ")
  192.               s = mid(s, i+1, len(s)-i)
  193.               send #Port, s;
  194.             else
  195.               send #Port,
  196.               s = ""
  197.             end if
  198.           end if
  199.         end if
  200.     end select
  201.   loop until CallerHungUp
  202.   send #Port,
  203.   send #Port,
  204.   send #Port, "Returning you to host mode"
  205.   send #Port,
  206. end sub
  207.  
  208. function YesNo(x as integer) as string
  209.   if x then
  210.     YesNo = "Yes"
  211.   else
  212.     YesNo = "No"
  213.   end if
  214. end function
  215.  
  216. declare function GetLine(prompt as string = "", maxlen as integer = 0, start as string = "", passchar as string = "") as string
  217. function GetLine(prompt as string, maxlen as integer, start as string, passchar as string) as string
  218.   dim s as string
  219.   dim starttime as DateTimeRec
  220.   dim warned as integer
  221.   call GetCurrentTime(starttime)
  222.   warned = false
  223.   s = start
  224.   send #Port, prompt; s;
  225.   do
  226.     dim c as string
  227.     c = inkey
  228.     if c = "" and not Local then
  229.       c = inkey(Port)
  230.     end if
  231.     select case c
  232.       case ""
  233.         dim idle as integer
  234.         idle = MinutesSince(starttime)
  235.         if idle >= 4 and not warned then
  236.           send #Port,
  237.           send #Port,
  238.           send #Port, "CAUTION!  You will be logged off if you do not continue in 60 seconds!"
  239.           send #Port,
  240.           send #Port, prompt; s;
  241.           warned = true
  242.         elseif idle >= 5 then
  243.           send #Port,
  244.           send #Port,
  245.           send #Port, "Logged off due to inactivity."
  246.           delay 1
  247.           hangup
  248.           ForceLogoff = True
  249.         end if
  250.       case "F2"
  251.         DoChat
  252.         send #Port, prompt; s;
  253.       case BS
  254.         if len(s) > 0 then
  255.           s = left(s, len(s)-1)
  256.           send #Port, BS;" ";BS;
  257.         end if
  258.       case CR
  259.         GetLine = s
  260.         send #Port,
  261.         exit function
  262.       case ESC
  263.         ' esc handling
  264.       case is >= " "
  265.         s = s + c
  266.         if len(passchar) > 0 then
  267.           send #Port, passchar;
  268.         else
  269.           send #Port, c;
  270.         end if
  271.         if maxlen > 0 and len(s) >= maxlen then
  272.           GetLine = s
  273.           exit function
  274.         end if
  275.     end select
  276.   loop until TimeLeft < 0 or CallerHungUp
  277.   GetLine = ""
  278. end function
  279.  
  280. function DisplayFile(fn as string) as integer
  281.   dim f as integer, count as integer
  282.   DisplayFile = TRUE
  283.   f = freefile
  284.   open fn for input as #f
  285.   count = 0
  286.   do while not eof(f)
  287.     dim s as string
  288.     input #f, s
  289.     send #Port, s
  290.     count = count + 1
  291.     if count >= 24 then
  292.       if OemUpper(GetLine("-Pause- [C]ontinue, [S]top? ", 1)) = "S" then
  293.         exit do
  294.       end if
  295.       send #Port,
  296.       count = 0
  297.     end if
  298.   loop
  299.   close #f
  300. catch err_fileopen
  301.   DisplayFile = FALSE
  302. end function
  303.  
  304. sub SendModemString(s as string)
  305.   dim i as integer, c as string
  306.   i = 1
  307.   while i <= len(s)
  308.     c = mid(s, i, 1)
  309.     if c = "^" and i+1 <= len(s) then
  310.       i = i + 1
  311.       c = mid(s, i, 1)
  312.       if c = "~" then
  313.         delay 0.5
  314.         goto nextchar
  315.       else
  316.         c = chr(asc(c) and 0x3f)
  317.       end if
  318.     end if
  319.     send c;
  320. nextchar:
  321.     i = i + 1
  322.   wend
  323. end sub
  324.  
  325. sub InitModem
  326.   dim result as string
  327.   hostecho off
  328.   if carrier then exit sub
  329.   timeout 5
  330. tryagain:
  331.   delay 1
  332.   SendModemString ModemSetup.init
  333.   do
  334.     receive result
  335.   loop until result = ModemSetup.ok
  336. catch err_timeout
  337.   goto tryagain
  338. end sub
  339.  
  340. function WaitForCall as integer
  341.   hostecho off
  342.   if carrier then
  343.     Local = False
  344.     Port = comm
  345.     WaitForCall = True
  346.     exit function
  347.   end if
  348.   do
  349.     dim rings as integer
  350.     rings = 0
  351.     dim result as string
  352.     do
  353.       dim c as string
  354.       c = inkey(comm)
  355.       if c = "" then
  356.         c = inkey
  357.         select case OemUpper(c)
  358.           case "F1"
  359.             if ModemSetup.busy <> "" then
  360.               SendModemString ModemSetup.busy
  361.               delay 1
  362.               flush input
  363.             end if
  364.             Local = True
  365.             Port = 0
  366.             WaitForCall = True
  367.             exit function
  368.           case "F7"
  369.             PackMessages
  370.             WaitForCall = False
  371.             exit function
  372.           case "F8"
  373.             SetupHost
  374.           case "F9"
  375.             print "Host mode terminated, returning to normal operation."
  376.             end
  377.         end select
  378.       elseif c = LF then
  379.         result = ""
  380.       else
  381.         result = result + c
  382.         if len(result) > len(ModemSetup.ring) then
  383.           result = right(result, len(result)-1)
  384.         end if
  385.         if result = ModemSetup.ring then
  386.           rings = rings + 1
  387.         end if
  388.       end if
  389.     loop until rings >= val(ModemSetup.ringcount)
  390.     delay 0.2
  391.     SendModemString ModemSetup.answer
  392.     timeout 60
  393.     do
  394.       receive result
  395.       if left(result, 7) = "CONNECT" then
  396.         ModemResult = result
  397.         BaudRate = val(right(ModemResult, len(ModemResult)-8))
  398.         Local = False
  399.         Port = comm
  400.         WaitForCall = True
  401.         exit function
  402.       end if
  403.     loop until result = "NO CARRIER"
  404.   loop
  405. catch err_timeout
  406.   WaitForCall = False
  407. end function
  408.  
  409. function NextField(s as string, delim as string) as string
  410.   dim i as integer
  411.   i = instr(s, delim)
  412.   if i > 0 then
  413.     NextField = left(s, i-1)
  414.     s = right(s, len(s)-i)
  415.   else
  416.     NextField = s
  417.     s = ""
  418.   end if
  419. end function
  420.  
  421. function LookupUser(uname as string, user as TUser) as integer
  422.   dim f as integer, s as string
  423.   LookupUser = False
  424.   f = freefile
  425.   open UserFileName for input as #f
  426.   do while not eof(f)
  427.     input #f, s
  428.     dim i as integer
  429.     i = instr(s, ";")
  430.     if i > 0 then
  431.       s = rtrim(left(s, i-1))
  432.     end if
  433.     if OemUpper(uname)+"," = left(s, len(uname)+1) then
  434.       user.Name = NextField(s, ",")
  435.       user.Password = NextField(s, ",")
  436.       user.Level = val(NextField(s, ","))
  437.       user.Phone = NextField(s, ",")
  438.       close #f
  439.       LookupUser = True
  440.       exit function
  441.     end if
  442.   loop
  443.   close #f
  444. catch err_fileopen
  445. end function
  446.  
  447. function GetPassword as integer
  448.   GetPassword = True
  449.   if User.Password = "" then
  450.     exit function
  451.   end if
  452.   GetPassword = False
  453.   dim password as string, tries as integer
  454.   do
  455.     password = GetLine("Password? ", 0, "", "*")
  456.     if CallerHungUp then
  457.       exit function
  458.     end if
  459.     if OemUpper(password) = OemUpper(User.Password) then
  460.       send #Port, "Password ok"
  461.       GetPassword = True
  462.       exit function
  463.     end if
  464.     tries = tries + 1
  465.     if tries > 3 then
  466.       send #Port,
  467.       send #Port, "Sorry, access denied"
  468.       send #Port,
  469.       exit function
  470.     else
  471.       send #Port,
  472.       send #Port, "Incorrect password entered"
  473.       send #Port,
  474.     end if
  475.   loop
  476.   GetPassword = True
  477. end function
  478.  
  479. function CallUserBack as integer
  480.   CallUserBack = False
  481.   if User.Phone = "" then
  482.     send #Port, "Your phone number is not on file."
  483.     send #Port, "(click)"
  484.     exit function
  485.   end if
  486.   send #Port, "Hanging up now, type ATA and press Enter after you get a ring."
  487.   delay 1
  488.   hostecho off
  489.   hangup
  490.   delay 10
  491.   send "ATDT"; User.Phone
  492.   timeout 60
  493.   dim result as string
  494.   do
  495.     receive result
  496.     if left(result, 7) = "CONNECT" then
  497.       ModemResult = result
  498.       BaudRate = val(right(ModemResult, len(ModemResult)-8))
  499.       exit do
  500.     end if
  501.   loop
  502.   timeout off
  503.   hostecho on
  504.   delay 1
  505.   send #Port, "Welcome "; User.Name
  506.   send #Port,
  507.   if GetPassword then
  508.     CallUserBack = True
  509.   end if
  510. catch err_timeout
  511.   send
  512. end function
  513.  
  514. function GetCallerInfo as integer
  515.   dim uname as string
  516.   do
  517.     uname = OemUpper(GetLine("Please enter your name? "))
  518.     if CallerHungUp then
  519.       GetCallerInfo = False
  520.       exit function
  521.     end if
  522.     if LookupUser(uname, User) then
  523.       if not GetPassword then
  524.         GetCallerInfo = False
  525.         exit function
  526.       end if
  527.       if Setup.modecallback and not Local then
  528.         if not CallUserBack then
  529.           GetCallerInfo = False
  530.           exit function
  531.         end if
  532.       end if
  533.       GetCallerInfo = True
  534.       exit function
  535.     elseif Setup.modeopen then
  536.       User.Name = uname
  537.       send #Port,
  538.       send #Port, "Your name ";chr(34);uname;chr(34);" was not found in the user list."
  539.       if OemUpper(left(GetLine("Is it spelled correctly? "), 1)) = "Y" then
  540.         exit do
  541.       end if
  542.       send #Port,
  543.     else
  544.       send #Port,
  545.       send #Port, "Sorry, you are not registered with this system."
  546.       send #Port, "(click)"
  547.       send #Port,
  548.       GetCallerInfo = False
  549.       exit function
  550.     end if
  551.   loop
  552.   send #Port,
  553.   do
  554.     dim password as string
  555.     User.Password = GetLine("Please select a password? ", 0, "", "*")
  556.     password      = GetLine("Type your password again? ", 0, "", "*")
  557.     if OemUpper(password) = OemUpper(User.Password) then exit do
  558.     send #Port,
  559.     send #Port, "The passwords you typed did not match.  Try again."
  560.     send #Port,
  561.   loop
  562.   User.Level = 0
  563.   open UserFileName for append as #1
  564.   print #1, User.Name;",";User.Password;",";User.Level
  565.   close #1
  566.   send #Port, "Welcome new user!"
  567.   GetCallerInfo = True
  568. catch err_fileopen
  569.   send "Fatal error - could not open user database"
  570.   GetCallerInfo = False
  571. end function
  572.  
  573. '$include 'hostfile.scr'
  574. '$include 'hostmsg.scr'
  575. '$include 'hostdos.scr'
  576.  
  577. sub HelpScreen
  578.   if DisplayFile(HelpFileName) then
  579.     do
  580.       dim s as string
  581.       send #Port,
  582.       send #Port, "Type the letter of the command you would like more help with,"
  583.       s = OemUpper(GetLine("or press Enter to return to the main menu: "))
  584.       if s = "" or CallerHungUp then exit do
  585.       send #Port,
  586.       if not DisplayFile(ConfigScriptPath+"\host" + left(s, 1) + ".hlp") then
  587.         send #Port, "Sorry, no help is available for that item."
  588.       end if
  589.     loop
  590.   else
  591.     send #Port, "Sorry, no help information is available."
  592.   end if
  593. end sub
  594.  
  595. ' Page sysop
  596.  
  597. sub PageSysop
  598.   send #Port, "Paging sysop..."
  599.   print "(Sysop: Press F2 to enter chat mode)"
  600.   play "RINGIN"
  601.   send #Port,
  602.   GetLine "Press Enter to continue? "
  603. end sub
  604.  
  605. sub Shutdown
  606.   if User.Level = 0 or Setup.shutdownpass = "" then
  607.     send #Port, "Sorry, shutdown option not available."
  608.     send #Port,
  609.     exit sub
  610.   end if
  611.   if OemUpper(GetLine("Enter shutdown password: ", 0, "", "*")) <> OemUpper(Setup.shutdownpass) then
  612.     send #Port,
  613.     send #Port, "Wrong password entered."
  614.     send #Port,
  615.     exit sub
  616.   end if
  617.   hangup
  618.   end
  619. end sub
  620.  
  621. do
  622.   PrelogFileName    = ConfigScriptPath+"\"+PrelogFileNamePart
  623.   MenuFileName      = ConfigScriptPath+"\"+MenuFileNamePart
  624.   ProtocolFileName  = ConfigScriptPath+"\"+ProtocolFileNamePart
  625.   LogoffFileName    = ConfigScriptPath+"\"+LogoffFileNamePart
  626.   HelpFileName      = ConfigScriptPath+"\"+HelpFileNamePart
  627.   UserFileName      = ConfigScriptPath+"\"+UserFileNamePart
  628.   MsgHeaderFileName = ConfigScriptPath+"\"+MsgHeaderFileNamePart
  629.   MsgDetailFileName = ConfigScriptPath+"\"+MsgDetailFileNamePart
  630.   LoadConfig
  631.   InitModem
  632.   do
  633.     cls
  634.     print "QmodemPro for Windows Host Mode"
  635.     print
  636.     print "Press F1 to log on locally"
  637.     print "Press F7 to pack the messages"
  638.     print "Press F8 to set up the host mode"
  639.     print "Press F9 to quit the host mode"
  640.     print
  641.     print "Modem ready for calls..."
  642.   loop until WaitForCall
  643.   timeout off
  644.   ForceLogoff = False
  645.   print "Call connected at "; BaudRate; " baud"
  646.   hostecho on
  647.   delay 1
  648.   send #Port, "Welcome to the Qmodem for Windows host mode!"
  649.   send #Port,
  650.   send #Port, "Modem result: "; ModemResult
  651.   send #Port, "Connected at "; BaudRate; " bps. ";
  652.   send #Port,
  653.   send #Port,
  654.   DisplayFile PrelogFileName
  655.   call GetCurrentTime(LogonTime)
  656.   call IncDateTime(LogonTime, LogoffTime, 0, val(Setup.MaxTime)*60)
  657.   if GetCallerInfo then
  658.     do
  659.       send #Port,
  660.       DisplayFile MenuFileName
  661.       dim cmd as string
  662.       cmd = GetLine("("+str(TimeLeft)+" min. left) Command? ")
  663.       send #Port,
  664.       select case OemUpper(cmd)
  665.         case "?"
  666.           HelpScreen
  667.         case "D"
  668.           DownloadFile
  669.         case "E"
  670.           EnterMessage
  671.         case "F"
  672.           ListFiles
  673.         case "G"
  674.           DisplayFile LogoffFileName
  675.           send #Port, "Thanks for calling!"
  676.           exit do
  677.         case "P"
  678.           PageSysop
  679.         case "R"
  680.           ReadMessages
  681.         case "S"
  682.           DosShell
  683.         case "U"
  684.           UploadFile
  685.         case "Z"
  686.           Shutdown
  687.         case else
  688.           send #Port, "Unknown command, try again"
  689.       end select
  690.     loop until TimeLeft < 0 or CallerHungUp
  691.   end if
  692.   hostecho off
  693.   if not Local then
  694.     delay 1
  695.     hangup
  696.     delay 1
  697.   end if
  698. loop
  699.